<?php

/**
 * Created by PhpStorm.
 * User: wenqiang.yq@gmail.com
 * Date: 16-3-2
 * Time: 上午10:46
 */


include_once dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . "ElasticSearch.php";
function add($i)
{
    $es = new \ElasticSearch\ElasticSearch("http://127.0.0.1:9200", "logstash-2015.05.19", "2012");
    $result = $es->data()->add([
            [
                "name" => time(),
                "age" => $i . rand(0, 1000),
                "high" => $i . rand(0, 1000),
                "p" => '1p0',
                "a" => '1a0',
                "c" => $i . rand(0, 1000),
                "f" => $i . rand(0, 1000),
                "v" => $i . rand(0, 1000),
            ]]
    );
}

function update()
{
    $es = new \ElasticSearch\ElasticSearch("http://127.0.0.1:9200", "server_log", "test_data");
    $result = $es->data()->update(
        [
            "id" => 'AVNLjzQRRUoxACyqBh0M',
            "name" => '55555555555'
        ]
    );
    print_r($result);
}


function replace()
{
    $es = new \ElasticSearch\ElasticSearch("http://127.0.0.1:9200", "server_log", "test_data");
    $result = $es->data()->replace(
        [
            "id" => "AVNLjzQRRUoxACyqBh0M",
            "name" => '45tttttttttttttttt'
        ]
    );
    print_r($result);
}


function health()
{
    $es = new \ElasticSearch\ElasticSearch("http://127.0.0.1:9200");
    $result = $es->es()->health();
    print_r($result);
}

function delete()
{
    $es = new \ElasticSearch\ElasticSearch("http://127.0.0.1:9200", "server_log", "test_data");
    $result = $es->data()->delete("AVNLeHQpRUoxACyqBh0K");
    print_r($result);
}

function exists()
{
    $es = new \ElasticSearch\ElasticSearch("http://127.0.0.1:9200", "server_log", "test_data");
    $result = $es->es()->exists("AVNLjzQRRUoxACyqBh0M");
    print_r($result);
}

function get()
{
    $es = new \ElasticSearch\ElasticSearch("http://127.0.0.1:9200", "server_log", "test_data");
    $result = $es->data()->get(array(5, 6, 7), "name,age");
    print_r($result);
}

function checkQueryStr()
{
    $es = new \ElasticSearch\ElasticSearch("http://127.0.0.1:9200", "server_log", "test_data");
    $result = $es->checkQueryStr(array(
        "querffy" => array(
            "filtered" => array(
                "query" => array(
                    "match_all" => array()
                )
            )
        )
    ));
    print_r($result);
}

function bodyQuery()
{
    $es = new \ElasticSearch\ElasticSearch("http://127.0.0.1:9200", "server_log", "test_data");
    $result = $es->bodyQuery(array(
        "query" => array(
            "filtered" => array(
                "query" => array(
                    "match" => array("name" => "文强")
                )
            )
        )
    ), "", "", "", 1);
    print_r($result->result());
}

function paramsQuery()
{
    $es = new \ElasticSearch\ElasticSearch("http://127.0.0.1:9200", "server_log", "test_data");
    $result = $es->paramsQuery("", "", "", "", 10);
    print_r($result->result());
}

function mapping()
{
    $es = new \ElasticSearch\ElasticSearch("http://127.0.0.1:9200", "server_log", "test_data");
    $result = $es->es()->mapping();
    print_r($result);
}


function analyze()
{
    $es = new \ElasticSearch\ElasticSearch("http://127.0.0.1:9200");
    $result = $es->es()->analyze("wo jiao xu wen qiang");
    print_r($result);
}

function template()
{
    $es = new \ElasticSearch\ElasticSearch("http://127.0.0.1:9200", "my_thread", "forums");
    $result = $es->search()->template("filter_terms", array("tid" => array("50154310", "50154556")));
    print_r($result->result() . "\n");
}

add(1);

